package com.hele.sts.pub;

import java.io.PrintStream;

public class PageController
{
  int currentPage;
  String description;
  boolean hasNext;
  boolean hasPrevious;
  int nextPage;
  int pageEndRow;
  int pageSize;
  int pageStartRow;
  int previousPage;
  boolean rowsAmountSet;
  int totalPages;
  int totalRowsAmount;
  
  public PageController()
  {
    this.pageSize = 15;
    this.currentPage = 1;
  }
  
  public PageController(int totalRows)
  {
    this.pageSize = 15;
    this.currentPage = 1;
    setTotalRowsAmount(totalRows);
  }
  
  public String description()
  {
    String description = "Total:" + getTotalRowsAmount() + " items " + getTotalPages() + " pages,Current page:" + this.currentPage + " Previous " + this.hasPrevious + " Next:" + this.hasNext + " start row:" + this.pageStartRow + " end row:" + this.pageEndRow;
    return description;
  }
  
  public int getCurrentPage()
  {
    return this.currentPage;
  }
  
  public String getDescription()
  {
    String description = "Total:" + getTotalRowsAmount() + " items " + getTotalPages() + " pages";
    return description;
  }
  
  public int getNextPage()
  {
    return this.nextPage;
  }
  
  public int getPageEndRow()
  {
    return this.pageEndRow;
  }
  
  public int getPageSize()
  {
    return this.pageSize;
  }
  
  public int getPageStartRow()
  {
    return this.pageStartRow;
  }
  
  public int getPreviousPage()
  {
    return this.previousPage;
  }
  
  public int getTotalPages()
  {
    return this.totalPages;
  }
  
  public int getTotalRowsAmount()
  {
    return this.totalRowsAmount;
  }
  
  public boolean isHasNext()
  {
    return this.hasNext;
  }
  
  public boolean isHasPrevious()
  {
    return this.hasPrevious;
  }
  
  public void setCurrentPage(int i)
  {
    this.currentPage = i;
    this.nextPage = (this.currentPage + 1);
    this.previousPage = (this.currentPage - 1);
    if (this.currentPage * this.pageSize < this.totalRowsAmount)
    {
      this.pageEndRow = (this.currentPage * this.pageSize);
      this.pageStartRow = (this.pageEndRow - this.pageSize + 1);
    }
    else
    {
      this.pageEndRow = this.totalRowsAmount;
      this.pageStartRow = (this.pageSize * (this.totalPages - 1) + 1);
    }
    if (this.nextPage > this.totalPages) {
      this.hasNext = false;
    } else {
      this.hasNext = true;
    }
    if (this.previousPage == 0) {
      this.hasPrevious = false;
    } else {
      this.hasPrevious = true;
    }
    System.out.println(description());
  }
  
  public void setHasNext(boolean b)
  {
    this.hasNext = b;
  }
  
  public void setHasPrevious(boolean b)
  {
    this.hasPrevious = b;
  }
  
  public void setNextPage(int i)
  {
    this.nextPage = i;
  }
  
  public void setPageSize(int i)
  {
    this.pageSize = i;
  }
  
  public void setPreviousPage(int i)
  {
    this.previousPage = i;
  }
  
  public void setTotalPages(int i)
  {
    this.totalPages = i;
  }
  
  public void setTotalRowsAmount(int i)
  {
    if (!this.rowsAmountSet)
    {
      this.totalRowsAmount = i;
      this.totalPages = (this.totalRowsAmount / this.pageSize + 1);
      setCurrentPage(1);
      this.rowsAmountSet = true;
    }
  }
}
